#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <map>
#include <climits>


using namespace std;

class Solution {
    vector<vector<int> > fgs;
    vector<int> X={1,-1,0,0};
    vector<int> Y={0,0,1,-1};
    int M,N,K,count;
    bool can(int m,int n){
        int ans=0;
        while(m){ans+=(m%10);m/=10;}
        while(n){ans+=(n%10);n/=10;}
        return ans>K;
    }
    void helper(int idx,int jdx){
        if(idx<0||jdx<0||idx>=M||jdx>=N||fgs[idx][jdx]||can(idx,jdx)){
            return ;
        }
        
        fgs[idx][jdx]=1;
        count++;
        for(int i=0;i<4;i++){
            int new_i=idx+X[i],new_j=jdx+Y[i];
            helper(new_i,new_j);
        }
    }
public:
    
    int movingCount(int m, int n, int k) {
        M=m,N=n,K=k;
        fgs=vector<vector<int> >(m,vector<int>(n,0));
        count=0;
        helper(0,0);
        return count;
    }
};


int main(){
    Solution s;
    cout<< s.movingCount(3,2,17)<<endl;



    return 0;
}